<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>我的会员_个人中心 - 胎大王</title>
	{include file='common/head' /}
</head>
<body>
<div class="container">
{include file='common/top' /}	
	<div class="usercenter">
		<div class="contai"><span class="f-bk30"></span>
			<div class="pure-g">
				{include file='common/usermenu' /}
				<div class="pure-u-1-24">&nbsp;</div>
				<div class="pure-u-18-24 right">
					<div class="con">
						<div class="f-bk30"></div>
						<button class="f-fr pure-button button-secondary" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-bars"></i> 添加</button>

						<div class="f-bk6"></div>
						<table class="pure-table usercenter-table">
						  <thead style="text-align:center">
						    <tr class=" f-textc">
						      <th>会员名</th>
						      <th>联系电话</th>
						      <th>注册日期</th>
						      <th>状态</th>
						      <th>操作</th>
						  	</tr>
						  </thead>
						  <tbody>
						  {empty name="data"}
						  <tr>
						  	<td colspan="5">
						  		<div style="text-align:center;padding:2rem 0;">
						  		  <img src="__IMG__/success.png">
						  		  <p style="color: #ec6c00;">暂无记录</p>
						  		</div>
						  	</td>
						  </tr>
						  {else /}
						  {volist name="data" id="vo"}
						    <tr class=" f-textc">
							<input type="hidden" value="{$vo.id}" />
						      <td>{$vo.name}</td>
						      <td>{$vo.mobile}</td>
						      <td>{$vo.createDate}</td>
							  <td>{$vo.isEnable}</td>
						      <td><button class="edit" class="f-fr pure-button button-secondary" data-toggle="modal" data-target="#exampleModal">编辑</button></td>
						    </tr>
						  {/volist}
						  {/empty}
						  </tbody>
						</table>
						<div class="usercenter-page">
							{if condition="$totalPages>1"}
								{volist name="total_arr" id="v"}
								<a href="/userlist.html?pageNumber={$v}" {if condition="$v eq $pageNumber"} class="act"{else /}{/if}>{$v}</a>
								{/volist}
							{else /}
							{/if}
						</div>
					</div>

				</div>
			</div>
		</div>
		<span class="f-bk30"></span>
	</div>
	{include file='common/foot' /}	
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">

  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="btn-info modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">修改信息</h4>
      </div>
      <div class="modal-body">
        <form  method="post" id="submitUser" class="form-horizontal" role="form">
          <div class="form-group">
            <label for="recipient-name" class="control-label">&emsp;联系人:</label>
            <input type="text" name="name" class="form-control well" id="modal-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">联系电话:</label>
            <input type="text" name="phone" class="form-control well" id="modal-phone">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">是否启用:</label>
            <input type="radio" name="isEnable" id="radiotrue" value="1" checked />是&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="radio" name="isEnable" id="radiofalse" value="0" />否
          </div>
		  <input type="hidden" name="id" value="add"/>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary modal-submit">确定</button>
      </div>
    </div>
  </div>
</div>

</div>
<script src="__JS__/layer/layer.js"></script>
<script>
$(function(){
	$('.modal-submit').click(function(){ 
		$(".modal-submit").attr({"disabled":"disabled"});
		var name = $("#modal-name").val();
		if(name==''||name==undefined||name==null){
			layer.alert("请填写联系人");
			$(".modal-submit").removeAttr("disabled");
			return false;
		}
		var phone = $("#modal-phone").val();
		if(!(/^1[3|4|5|6|7|8|9]\d{9}$/.test(phone))){
			layer.alert("手机号码有误，请重填");
			$(".modal-submit").removeAttr("disabled");
			return false;
		}
		var isEnable = $("input[name='isEnable']:checked").val();
		var id = $("input[name='id']").val();
		if(id=='add'){
			$.ajax({
				url: "/Member/addUser.html",
				type: "POST",
				data: {name:name,phone:phone,isEnable:isEnable},
				dataType: "json",
				cache: false,
				success: function(data) {
					if(data.code==1){
						window.location.href='/userlist.html';					
					}else{
						layer.alert(data.msg);
						$(".modal-submit").removeAttr("disabled");
					}
				}
			});			
		}else{
			$.ajax({
				url: "/Member/editUser.html",
				type: "POST",
				data: {id:id,name:name,phone:phone,isEnable:isEnable},
				dataType: "json",
				cache: false,
				success: function(data) {
					if(data.code==1){
						window.location.href='/userlist.html';					
					}else{
						layer.alert(data.msg);
						$(".modal-submit").removeAttr("disabled");
					}
				}
			});		
		}		
	});
	$('.edit').click(function(){ 
		var id = $(this).parents('tr').find("input[type='hidden']").val();
		$.ajax({
			url: "/Member/detailUser.html",
			type: "POST",
			data: {id:id},
			dataType: "json",
			cache: false,
			success: function(data) {
				if(data.code==1){
					$("#modal-name").val(data.data.name);					
					$("#modal-phone").val(data.data.mobile);
					if(data.data.IsEnable==1){

						$("#radiotrue").attr('checked','true');;
					}else{

						$("#radiofalse").attr('checked','true');;
					}
					$("input[name='id']").val(data.data.id);
				}else{
					layer.alert(data.msg);
				}
			}
		});		
	});		
});
</script>
</body>
</html>